<template>
	<view class="ewm">
		<image :src="active?content.qrcode:content.receipt_qrcode||'/pagesB/static/微信图片_20201124091755.png'" mode=""></image>
		<view class="text">{{active?'扫描二维码成为我的粉丝':'扫描二维码付款给我'}}</view>
		<view class="Bottom" @click="change">
			<image src="/pagesB/static/QRcode_turn@2x.png" mode=""></image><text>{{active?'切换为收货码':'切换为个人码'}}</text></view>
	</view>
</template>

<script>
	import md5 from '@/common/api/md5.js'
	import {requestUrl} from '@/common/config.js'
	export default {
		data() {
			return {
				content:'',
				active:true,
			};
		},
		onShow() {
			if(uni.getStorageSync('access_token')){
			this.access_token=JSON.parse(uni.getStorageSync('access_token'))
			}else{
				uni.showModal({
				    title: '提示',
				    content: '你还未登录，请先登录',
				    success: function (res) {
				        if (res.confirm) {
							uni.navigateTo({
								url:'/pages/login/login'
							})
				        } else if (res.cancel) {
				        }
				    }
				});
			}
			let time = Math.round(new Date().getTime() / 1000).toString()
			let _this = this
			let Time = ['time', time].join('=')
			let Access_token = ['access_token', this.access_token].join('=')
			let content = ['content=pinet.FeiMao.2017'].join()
			let arr = [content, Time].sort(function(a, b) {
				a - b
			})
			let newarr = md5(arr.join('&'))
			uni.request({
				url: requestUrl+'/app/user/getQrcode',
				method: "GET",
				data: {
					access_token: this.access_token,
					time: time,
					sign: newarr
				},
				success: function(res) {
					console.log(res)
					if(res.data.errcode==0){
						_this.content=res.data.content
					}
				}
			});
		},
		methods:{
			change(){
				this.active=!this.active
			}
		}
	}
</script>

<style lang="less">
	.ewm{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		>image{
			width: 540rpx;
			height: 540rpx;
			margin: 58rpx 0 46rpx ;
		}
		>.text{
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #9DA5A8;
			margin-bottom: 106rpx;
		}
		.Bottom{
			width: 540rpx;
			height: 80rpx;
			border-radius: 20px;
			display: flex;
			justify-content: center;
			align-items: center;
			// background: url(../../../../static/QRcode_turn@2x.png) no-repeat 0px 0px;
			background-color: #DB1B22;
			// background-size: 32rpx 32rpx;
			text{
				font-size: 34rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				margin-left: 20rpx;
			}
			image{
				width: 32rpx;
				height: 32rpx;
			}
		}
	}
</style>
